<?php #include("./include/inc_asegurar.php"); ?>

	<div id="masthead">
		
		<div class="content_pad">
			
			<h1 class="no_breadcrumbs">Proveedores</h1>
			
		</div> <!-- .content_pad -->
		
	</div> <!-- #masthead -->	
	
	<div id="content" class="xgrid">
			
		<div class="x12">
			
			<h2>Listado de proveedores</h2>
			
			<?php if( f_validar_permiso($_SESSION["perf_codigo"], 21, 1, $conn)) { ?>
			<p>
				<a class="btn-icon btn-grey btn-plus" href="?proveedor_edit&a=agregar"><span></span>Agregar proveedor</a>
			</p>
			<?php } ?>
			
			<table class="data display datatable">
				<thead>
					<tr>
						<th><span title="C&oacute;digo">Cod.</a></th> 
						<th><span title="RUT">RUT</a></th> 
						<th><span title="Razón social">Razón social</a></th> 
						<th><span title="Rubro">Rubro</a></th>
						<th><span title="Comuna">Comuna</a></th>
						<th><span title="Acci&oacute;n">Acci&oacute;n</a></th>
					</tr>
				</thead>
				<tbody>
				<?php
				
					$Q_select  = " SELECT ";
					$Q_select .= " prov_codigo,  ";
					$Q_select .= " prov_rut,  ";
					$Q_select .= " prov_dv,  ";
					$Q_select .= " prov_razon_social,  ";
					$Q_select .= " prov_giro,  ";
					$Q_select .= " prov_rubro,  ";
					$Q_select .= " comuna ";
					$Q_select .= " from proveedores ";
					$Q_select .= " inner join proveedores_contactos ";
					$Q_select .= " on prov_codigo = provcon_c_proveedores ";
					$Q_select .= " inner join comuna ";
					$Q_select .= " on provcon_c_comuna = id_comuna ";
					$Q_select .= " where prov_e_proveedores = 1 ";

					$Res_Q_select = mysql_query( $Q_select,$conn );
					
					while ( $Reg_Q_select = mysql_fetch_array( $Res_Q_select ) ){
						
						$ii_c_proveedor	= $Reg_Q_select["prov_codigo"];
						$is_rut 		= $Reg_Q_select["prov_rut"]."-".$Reg_Q_select["prov_dv"] ;
						$is_razon_social = $Reg_Q_select["prov_razon_social"];
						$is_giro		= $Reg_Q_select["prov_giro"];
						$is_rubro		= $Reg_Q_select["prov_rubro"];
						$is_comuna		= $Reg_Q_select["comuna"];

					?>
					<tr>
						<td><?php echo $ii_c_proveedor; ?></td> 
						<td><?php echo $is_rut; ?></td>
						<td><?php echo $is_razon_social; ?></td>
						<td><?php echo $is_rubro; ?></td>
						<td><?php echo $is_comuna; ?></td> 
						<td>
						<?php if( f_validar_permiso($_SESSION["perf_codigo"], 21, 3, $conn)) { ?>
							<a href="?proveedor_edit&a=editar&ii_c_proveedor=<?php echo $ii_c_proveedor; ?>">[Editar]</a>
						<?php } ?>
						<?php if( f_validar_permiso($_SESSION["perf_codigo"], 21, 4, $conn)){ ?>
							<a href="?proveedor_edit&a=eliminar&ii_c_proveedor=<?php echo $ii_c_proveedor; ?>">[Eliminar]</a>
						<?php } ?>
						<?php if( f_validar_permiso($_SESSION["perf_codigo"], 22, 2, $conn)){ ?>
							<a href="?nota_proveedor&ii_c_proveedor=<?php echo $ii_c_proveedor; ?>">[Notas]</a>
						<?php } ?>
						<?php /* if( f_validar_permiso($_SESSION["perf_codigo"], 23, 2, $conn)){ ?>
							<a href="?cta_cte_proveedor&ii_c_proveedor=<?php echo $ii_c_proveedor; ?>">[Cta Cte]</a>
						<?php } */ ?>
						</td>
					</tr>
					<?php } ?>					
				</tbody>
			</table>
			 
		</div>  
		
	</div> <!-- #content -->